package com.wandian.xml;

import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;

import com.wandian.executor.TimerCommand;
import com.wandian.texas.BaseCommandObject;
import com.wandian.texas.CalculateCard;
import com.wandian.texas.GameData;
import com.wandian.texas.SessionObject;
import com.wandian.texas.entity.GameRoomEntity;
import com.wandian.texas.entity.SNAPCARDS;
import com.wandian.texas.entity.UserGameEntity;
import com.wandian.texas.entity.UserInfoEntity;

/**
 * @author long
 * @Create 2012-10-18 下午4:17:08
 * @QQ 108232706
 * @version 1.0
 * @description RoomConfigItem
 */
public class RoomConfigItem {

	public int id;
	public int roomCode;
	public AtomicBoolean canSetRoom = new AtomicBoolean(true);
	public int begin;
	public int end;
	public float minBlind = 100;
	public float maxBlind = 200;
	public float minTake = 1000;
	public float maxTake = 5000;
	public float newChip = 200;
	public int seat = 9;
	public int maxplayer;
	//	private String name;
	public byte vip;
	public short serverid;
	public int bettime = 15;
	public Date startTime;
	public Date endTime;
	public boolean isLock = false;
	public String pwd;

	//	public DataPacket dataPacket = new DataPacket();
	/**
	 * 是否洗牌到积宝，防止洗牌再次出积宝,一交换请求段只出一个
	 */
	public boolean isGenerateCornucopia() {
		return gameRoom.isGenerateCornucopia;
	}

	public void isGenerateCornucopia(boolean isGenerateCornucopia) {
		gameRoom.isGenerateCornucopia = isGenerateCornucopia;
	}

	// 积宝控制
	/**
	 * 中心服务器告诉游戏服务器下把是否可以出积宝
	 */
	public boolean isAllowCornucopia() {
		return gameRoom.isAllowCornucopia;
	}

	public void isAllowCornucopia(boolean isAllowCornucopia) {
		gameRoom.isAllowCornucopia = isAllowCornucopia;
	}

	/**
	 * 游戏当局有没有正在使用积宝指标
	 */
	public boolean isUsingCornucopia() {
		return gameRoom.isUsingCornucopia;
	}

	public void isUsingCornucopia(boolean isUsingCornucopia) {
		gameRoom.isUsingCornucopia = isUsingCornucopia;
	}

	/**
	 * 游戏服务器告诉中心服务器积宝有没有发出去
	 */
	public boolean isCornucopiaSend() {
		return gameRoom.isCornucopiaSend;
	}

	public void isCornucopiaSend(boolean isCornucopiaSend) {
		gameRoom.isCornucopiaSend = isCornucopiaSend;
	}

	/**
	 * 洗牌到积宝时候积宝牌型
	 */
	public int cornucopiaCardType() {
		return gameRoom.cornucopiaCardType;
	}

	public void cornucopiaCardType(int cornucopiaCardType) {
		gameRoom.cornucopiaCardType = cornucopiaCardType;
	}

	/**
	 * 洗牌到积宝时候玩家id
	 */
	public int cornucopiaUserId() {
		return gameRoom.cornucopiaUserId;
	}

	public void cornucopiaUserId(int cornucopiaUserId) {
		gameRoom.cornucopiaUserId = cornucopiaUserId;
	}

	public int cornucopiaidx() {
		return gameRoom.cornucopiaidx;
	}

	public void cornucopiaidx(int cornucopiaidx) {
		gameRoom.cornucopiaidx = cornucopiaidx;
	}

	/**
	 * 当前积宝标识，中心服务器返回的
	 */
	public String cornucopiaCallBack() {
		return gameRoom.cornucopiaCallBack;
	}

	public void cornucopiaCallBack(String cornucopiaCallBack) {
		gameRoom.cornucopiaCallBack = cornucopiaCallBack;
	}

	/**
	 * 洗牌到积宝时候坐位id
	 */
	public int cornucopiaSeatId() {
		return gameRoom.cornucopiaSeatId;
	}

	public void cornucopiaSeatId(int cornucopiaSeatId) {
		gameRoom.cornucopiaSeatId = cornucopiaSeatId;
	}

	/**
	 * 模拟测试的公共牌
	 */
//	public String[] testPublicCards = new String[5];

	/**
	 * 准备发一个命令的数据包
	 * 
	 * @param cmdId
	 */
	/*public void writeBegin(short cmdId) {
		dataPacket.cmdId = cmdId;
		dataPacket.writeBegin();
	}

	public void writeByte(byte value) {
		dataPacket.writeByte(value);
	}

	public void writeBytes(byte[] bytes) {
		dataPacket.writeBytes(bytes);
	}

	public void writeShort(Short value) {
		dataPacket.writeShort(value);
	}

	public void writeInt(int value) {
		dataPacket.writeInt(value);
	}

	public void writeString(String msg) {
		dataPacket.writeString(msg);
	}

	public void writeEnd() {
		dataPacket.writeEnd();
	}

	public void broadCastToRoomUsers() {
		UserMgr.I().broadCastToRoomUsers(this.id, dataPacket);
	}*/

	// 存档game
	public int gameId() {
		return gameRoom.GameId;
	}

	public GameRoomEntity gameRoom() {
		return gameRoom;
	}

	public SNAPCARDS SNAPCARDS() {
		return gameRoom.snapCards;
	}

	public void SNAPCARDS(SNAPCARDS snapCards) {
		gameRoom.snapCards = snapCards;
	}

	public void clearUserStep() {
		gameRoom.clearUserStep();
	}

	public int currPublicCardLen() {
		return gameRoom.currPublicCardLen;
	}

	public void currPublicCardLen(int currPublicCardLen) {
		gameRoom.currPublicCardLen = currPublicCardLen;
	}

	public int dealer() {
		// 发牌者，庄家
		return gameRoom.getDealerId();
	}

	public int curTime() {
		// 游戏若开始，倒计时的数
		return this.getLeftTime();
	}

	public TimerCommand timer() {
		return gameRoom.timer;
	}

	/**
	 * @param cmdObject
	 */
	public void startTimer(int type, int roomId, BaseCommandObject cmdObject, UserInfoEntity user) {
		gameRoom.startTimer(type, roomId, cmdObject, user);
	}

	public void startTimer(int type, RoomConfigItem room, BaseCommandObject cmdObject) {
		gameRoom.startTimer(type, room, cmdObject);
	}

	public void startTimer(int type) {
		gameRoom.startTimer(type);
	}

	public void putTimerParams(String key, Object value) {
		gameRoom.putTimerParams(key, value);
	}

	public boolean cancel() {
		return gameRoom.cancel();
	}

	public boolean boolCanncel() {
		return gameRoom.boolCanncel;
	}

	public int getLeftTime() {
		return gameRoom.getLeftTime();
	}

	public String memo() {
		return gameRoom.stepMemo;
	}

	public void stepMemo(String stepMemo) {
		gameRoom.stepMemo = stepMemo;
	}

	public void stepMemoContact(String stepMemo) {
		gameRoom.stepMemo += stepMemo;
	}

	public float giveChip() {
		return gameRoom.giveChip;
	}

	public void giveChip(float giveChip) {
		gameRoom.giveChip = giveChip;
	}

	public void delay(long delay) {
		gameRoom.delay(delay);
	}

	public void delay(long delay, TimeUnit _unit) {
		gameRoom.delay(delay, _unit);
	}

	public void reset() {
		gameRoom.reset();
	}

	public String[] PublicCards() {
		return gameRoom.PublicCard;
	}

	public String PublicCards(int index) {
		return gameRoom.PublicCard[index];
	}

	public int publicCardLen = 5;

	/**
	 * 玩家加注增加
	 * 
	 * @param SeatId
	 * @param addChip
	 */
	public void callChip(int SeatId, float addChip) {
		gameRoom.callChip(SeatId, addChip);
	}

	/**
	 * 下注增加到
	 * 
	 * @param SeatId
	 * @param callChip
	 */
	//	public void callChipTo(int SeatId, int callChip) {
	//		gameRoom.callChipTo(SeatId, callChip);
	//	}

	/**
	 * 返回该回合坐位上桌面的总额
	 * 
	 * @param SeatId
	 * @return
	 */
	public float callChip(int SeatId) {
		return gameRoom.callChip(SeatId);
	}

	/**
	 * 每一回合开始,桌上下注清空
	 */
	public void clearSeatChip() {
		gameRoom.clearSeatChip();
	}

	public int bonusPoolLen = 0;

	public float[] bonusPools() {
		return gameRoom.BonusPools;
		// = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
	}

	public float bonusPool(int bonusIndex) {
		return gameRoom.BonusPools[bonusIndex];
	}

	public int curBonusIndex() {
		return gameRoom.curBonusIndex;
	}

	public float curSeatChip(int seatId) {
		return gameRoom.curSeatChip(seatId);
	}

	public float curSeatTotalChip(int seatId) {
		return gameRoom.curSeatTotalChip(seatId);
	}

	public void InBonusPool() {
		gameRoom.InBonusPool();
	}

	public void AddBonusPool() {
		gameRoom.AddBonusPool();
	}

	public int BonusPoolsSize() {
		return gameRoom.BonusPoolsSize();
	}

	public void clearBonusPool() {
		gameRoom.clearBonusPool();
	}

	public void CalculateWinner(int dbIndex) {
		// 计算每个边池的赢家
		gameRoom.CalculateWinner(dbIndex);
	}

	// <----CMD_OPERATION_NEXT
	public int curSeatId() {
		return gameRoom.curSeatId;
	}

	public boolean containGameUser(UserInfoEntity user) {
		return gameRoom.containGameUser(user);
	}

	//	public boolean contain9SeatUser(SessionObject session) {
	//		return gameRoom.contain9SeatUser(session);
	//	}

	public boolean containUserSeat(Integer seatId) {
		return gameRoom.containUserSeat(seatId);
	}

	public boolean containWaitSeat(Integer seatId) {
		return gameRoom.containWaitSeat(seatId);
	}

	public boolean boolShowCard() {
		return gameRoom.boolShowCard;
	}

	public void boolShowCard(boolean boolShowCard) {
		gameRoom.boolShowCard = boolShowCard;
	}

	public synchronized void addFoldCount() {
		gameRoom.foldCount++;
	}

	public void addAllInCount() {
		gameRoom.allinCount++;
	}

	public boolean isGameOver() {
		synchronized (gameRoom.gameUsers) {
			return gameRoom.isGameOver();
		}

	}

	public boolean doingGameOver() {
		return gameRoom.doingGameOver;
	}

	public void doingGameOver(boolean doingGameOver, int dbIndex) {
		gameRoom.doingGameOver = doingGameOver;
		//如果在这里就算出游戏结果,就好了
		if (doingGameOver/* && !gameRoom.lastLeaveGameOver*/) {
			//			gameRoom.doingGameOver();
			//入池
			this.InBonusPool();
			this.clearSeatChip();
			//计算赢家
			this.CalculateWinner(dbIndex);
		}
	}

	public int resetStandMaxRaiser() {
		return gameRoom.resetStandMaxRaiser();
	}

	public void curSeatId(int curSeatId) {
		//		Log.debug("<<===========当前curSeatId变为==============>>:" + curSeatId);
		gameRoom.curSeatId = curSeatId;
	}

	/**
	 * 当前桌上最小筹码
	 * 
	 * @return
	 */
	public float minCall() {
		return gameRoom.minCall;
	}

	public void minCall(float minCall) {
		gameRoom.minCall = minCall;
	}

	public float minRaise() {
		return gameRoom.minRaise;
	}

	public void minRaise(float minRaise) {
		gameRoom.minRaise = minRaise;
	}

	public float maxRaise() {
		return gameRoom.maxRaise;
	}

	public void maxRaise(float maxRaise) {
		gameRoom.maxRaise = maxRaise;
	}

	public float MinBind() {
		return gameRoom.MinBind;
	}

	public int MinBindSeatId() {
		return gameRoom.MinBindSeatId;
	}

	public int MinBindUserId() {
		return gameRoom.MinBindUserId;
	}

	public int MaxBindSeatId() {
		return gameRoom.MaxBindSeatId;
	}

	public float MaxBind() {
		return gameRoom.MaxBind;
	}

	public int MaxBindUserId() {
		return gameRoom.MaxBindUserId;
	}

	/**
	 * 最大加注者(如果收到操作请求,处理完之后,判断下一个seat是不是最大者,若是则翻牌操作,
	 * ,第1回{大盲下一个->大盲(Raiser)}，初始是大盲
	 * (第一回给大盲最少一次操作机会,若大盲的callChip=MaxBind,则给操作,否则翻牌))
	 * 第2回{庄家下一个【小盲(Raiser)】->庄家,如果操作到了第2回的最大加注者结束(),转牌}
	 * 第3回{庄家下一个【小盲(Raiser)】->庄家,如果操作到了第3回的最大加注者结束(),河牌}
	 * 第4回{庄家下一个【小盲(Raiser)】->庄家,如果操作到了第4回的最大加注者结束(), Game_Over} 起始者可以顺时针推
	 * 
	 * @return
	 */
	public int maxRaiseSeatId() {
		return gameRoom.maxRaiseSeatId;
	}

	/**
	 * 每轮结束，重置出牌
	 */
	public void resetMaxRaiseSeat() {
		gameRoom.resetMaxRaiseSeat();
	}

	public void maxRaiseSeatId(int maxRaiseSeatId) {
		gameRoom.maxRaiseSeatId = maxRaiseSeatId;
	}

	/**
	 * 记录的是本次操作的筹码,每个玩家当前一次下注的金额的最大值(allin的下注太少,不能作为基准点),fold弃牌玩家排除(失去所有权)
	 * 看牌Chek,因为没有增多，所以不能更新,只有Raise,加注的,Stake才加callChip
	 * 
	 * @return
	 */
	public float stake() {
		return gameRoom.stake;
	}

	public void stake(float stake) {
		gameRoom.stake = stake;
		// Log.debug("当前房间游戏stake变成," + stake);
	}

	public int fold() {
		return gameRoom.fold;
	}

	public int step() {
		return gameRoom.step;
	}

	public int stepUser(int seatId) {
		return gameRoom.gameOverUsers[seatId - 1].step();
	}

	public int userStep(int seatId) {
		return gameRoom.gameOverUsers[seatId - 1].step;
	}

	/**
	 * 放弃操作,人数加，返回游戏是否剩余1人,以便结束
	 * 
	 * @return
	 */
//	public boolean addFold() {
//		gameRoom.fold++;
//		return gameRoom.fold >= this.gameUsersSize() - 1;
//	}

	public void step(int step) {
		gameRoom.step = step;
	}

	public void operateStep() {
		gameRoom.step++;
	}

	public void operateStake(int AddChip) {
		gameRoom.stake += AddChip;
	}

	// CMD_OPERATION_NEXT--->
	// public int totalNum() {
	// Log.debug("当前房间" + this.id + "总人数:" + gameRoom.totalNum);
	// return gameRoom.totalNum;
	// }
	//
	// public int totalNumAdd(int value) {
	// Log.debug("当前房间" + this.id + "总人数:" + (gameRoom.totalNum +
	// value));
	// return gameRoom.totalNum += value;
	// }
	//
	// public void totalNum(int totalNum) {
	// Log.debug("当前房间" + this.id + "总人数:" + gameRoom.totalNum);
	// gameRoom.totalNum = totalNum;
	// }

	// public int seatPlayerNum() {
	// return gameRoom.seatPlayerNum;
	// // 坐下来的人数
	// }
	//
	// public int seatPlayerNumAdd(int value) {
	// return gameRoom.seatPlayerNum += value;
	// // 坐下来的人数
	// }
	//
	// public void seatPlayerNum(int seatPlayerNum) {
	// gameRoom.seatPlayerNum = seatPlayerNum;
	// // 坐下来的人数
	// }

	public int playingPlayerNum;// 正在玩游戏的人数
	public GameRoomEntity gameRoom = new GameRoomEntity();

	// public Map<Integer, SessionObject> SeatMap = new
	// ConcurrentHashMap<Integer, SessionObject>(9);//房间坐位玩家，1-9

	public RoomConfigItem(int _id, int _roomCode) {
		this.id = _id;
		this.roomCode = _roomCode;
		this.gameRoom.RoomId = _id;
		this.gameRoom.RoomCode = _roomCode;
		this.gameRoom.ServerId = GameData.SERVER.ServerId;
	}

	public boolean isPlaying() {
		return this.gameRoom.isPlaying;
	}

	public void isPlaying(boolean isPlaying) {
		this.gameRoom.isPlaying = isPlaying;
	}

	// public void setIsPlaying(boolean isPlaying) {
	// this.Game.isPlaying = isPlaying;
	// }

	/**
	 * @param seatId
	 * @return
	 */
	public SessionObject getUserBySeatId(int seatId) {
		if (seatId > 0 && seatId < 10) {
			return gameRoom.seatUsers[seatId - 1];
		}
		return null;
	}

	public SessionObject[] seatUsers() {
		return gameRoom.seatUsers;
	}

//	public int[] userSeats() {
//
//		return gameRoom.userSeats;
//	}

	/**
	 * 当玩家坐下时候，若位置没有人坐，则可以坐，如果游戏没有开始，那么把座位号保存在userSeats里，否则保存在等候组 <br/>
	 * 在下次开始的时候，将等候组的加入userSeats里
	 * 
	 * @param user
	 * @param seatId
	 * @return
	 */
	public boolean sitDown(SessionObject user, int seatId) {
		if (seatId > 0 && seatId < 10) {
			if (getUserBySeatId(seatId) == null) {
				gameRoom.seatUsers[seatId - 1] = user;
				if (this.isPlaying()) {
//						if (gameRoom.waitSeats[seatId] < 1) {
//							gameRoom.waitSeats[seatId] = user.getUser().userId;
//							gameRoom.waitSeatsLen++;
//						}
					if (CalculateCard.add(gameRoom.waitSeats, gameRoom.waitSeatsLen, seatId)) {
						gameRoom.waitSeatsLen++;
					}
					//						Log.debug("游戏开始，座位来人进入等待区，seat:" + seatId);
				} else {
//						if (gameRoom.userSeats[seatId] < 1) {
//							gameRoom.userSeats[seatId] = user.getUser().userId;
//							gameRoom.userSeatsLen++;
//						}
					if (CalculateCard.add(gameRoom.userSeats, gameRoom.userSeatsLen, seatId)) {
						gameRoom.userSeatsLen++;
					}
					//						Log.debug("游戏没有开始，座位来人进入游戏区，seat:" + seatId);
				}
//					Log.debug(String.format("[RoomConfigItem]玩家坐下成功,user:%s,坐位:%s", user.getUser().nickName, seatId));
				if (roomSeatSize() == 1) {
					this.isPlaying(false);
				}
				return true;
			}
		}
		//		Log.debug(String.format("[RoomConfigItem]玩家坐下失败,user:%s,坐位:%s", user.getUser().nickName, seatId));
		return false;
	}

	/**
	 * 玩家站起来，在两个用户组都删除,坐位站起锁
	 * 
	 * @param user
	 * @param seatId
	 * @return
	 */
	public boolean standUp(SessionObject user, int seatId) {
		if (seatId > 0 && seatId < 10) {
			gameRoom.seatUsers[seatId - 1] = null;
			if (CalculateCard.remove(gameRoom.userSeats, gameRoom.userSeatsLen, seatId)) {
				gameRoom.userSeatsLen--;
			}
			if (CalculateCard.remove(gameRoom.waitSeats, gameRoom.waitSeatsLen, seatId)) {
				gameRoom.waitSeatsLen--;
			}
//				if (gameRoom.userSeats[seatId] > 0) {
//					gameRoom.userSeatsLen--;
//					gameRoom.userSeats[seatId] = 0;
//				}
//				if (gameRoom.waitSeats[seatId] > 0) {
//					gameRoom.waitSeatsLen--;
//					gameRoom.waitSeats[seatId] = 0;
//				}

			// gameRoom.gameUsers.remove(user);
			//			Log.debug(String.format("[RoomConfigItem]玩家起立成功,user:%s,坐位:%s", user.getUser().nickName, seatId));
			return true;

		}
		//		Log.debug(String.format("[RoomConfigItem]玩家起立失败,user:%s,坐位:%s", user.getUser().nickName, seatId));
		return false;

	}

	/**
	 * 从游戏组站起锁
	 * @param session
	 */
	public void standUp(int dbIndex, SessionObject session) {
		gameRoom.GameSeatLock.lock();
		try {
			gameRoom.standUp(session, dbIndex);
		} finally {
			gameRoom.GameSeatLock.unlock();
		}

	}

	@Override
	public String toString() {
		/*StringBuilder sb = new StringBuilder();
		ArrayList<SessionObject> roomUsers = roomUsers();
		for (SessionObject s : roomUsers) {
			sb.append(s.getUser() + "|");
		}*/
		return String.format("[Room]:%s,%s,最大小筹码%s %s,大小盲注%s %s [Game]:%s", this.id, this.isPlaying() ? "正在游戏" : "等待", this.minTake, this.maxTake, this.minBlind, this.maxBlind, this.gameRoom.toString());
	}

	// <---seatUsers
	/**
	 * 根据坐位找session
	 * 
	 * @param seatId
	 * @return
	 */
	public SessionObject seatUsers(int seatId) {
		return gameRoom.seatUsers(seatId);
	}

	/**
	 * 根据玩家在userSeat里的索引，找到其session
	 * 
	 * @param index
	 * @return
	 */
//	public SessionObject seatSessionByIndex(int index) {
//		if (index >= gameRoom.userSeats.size())
//			return null;
//		return gameRoom.seatUsers(this.userSeats().get(index));
//	}

	/**
	 * 根据玩家在userSeat里的索引，找到其user
	 * 
	 * @param index
	 * @return
	 */
//	public UserInfoEntity seatUserByIndex(int index) {
//		return this.seatSessionByIndex(index).getUser();
//	}

	/**
	 * 根据坐位找session
	 * 
	 * @param seatId
	 * @return
	 */
	public UserInfoEntity getUser(int seatId) {
		return gameRoom.getUser(seatId);
	}

	/**
	 * 坐位上玩家数量,userSeats size
	 * 
	 * @return
	 */
	public int roomSeatSize() {
		return gameRoom.userSeatsLen + gameRoom.waitSeatsLen;
	}

	public com.wandian.util.ArrayList<UserInfoEntity> gameUsers() {
		return gameRoom.gameUsers;
	}

	public com.wandian.util.ArrayList<SessionObject> GameSessions() {
		return gameRoom.gameSessions;
	}

	public UserGameEntity GameUser(int index) {
		return gameRoom.gameOverUsers[index];
	}

	public int gameUsersSize() {
		int count = gameRoom.gameUsers.size();
		// if (count < 2) {
		// gameRoom.isNewGame = true;
		// }
		return count;
	}

	/**
	 * 玩游戏的人数
	 * 
	 * @return
	 */
	public int roomGameSeatSize() {
		return gameRoom.userSeatsLen;
	}

	// seatUsers--->
	// <----------------RoomUsers----
	public ArrayList<SessionObject> roomUsers() {
		return gameRoom.roomUsers;
	}

	/**
	 * f房间玩家数量 roomUsers size
	 * 
	 * @return
	 */
	public int roomUserSize() {
		return gameRoom.roomUsers.size();
	}

	public void beforStartGame() {
		gameRoom.beforStartGame();
	}

	public boolean addRoomUser(SessionObject session) {
		if (containsRoomUser(session)) {
			return false;
		}
		return gameRoom.roomUsers.add(session);
	}

	public boolean removeRoomUser(SessionObject session) {
		return gameRoom.roomUsers.remove(session);
	}

	public boolean containsRoomUser(SessionObject session) {
		return gameRoom.roomUsers.contains(session);
	}

	public ReentrantLock GameSeatLock() {
		return gameRoom.GameSeatLock;
	}

	public ReentrantLock RoomDoorLock() {
		return gameRoom.RoomDoorLock;
	}

	/**
	 * 进入房间，加把房门锁
	 * @param session
	 * @return
	 */
	public boolean inGame(SessionObject session) {
		gameRoom.RoomDoorLock.lock();
		try {
			if (!this.containsRoomUser(session)) {
				this.addRoomUser(session);
				session.getUser().roomId = this.id;
				session.getUser().state = GameData.LOOK_ON;
				// 当前房间要增加
				// room.totalNumAdd(1);
				//				Log.debug(String.format("玩家%s进入房间:%s 成功.当前总人数", session.getUser().nickName, roomid, room.roomUserSize()));
				return true;
				// room.playerNum++;
			}
			//			Log.debug(String.format("玩家%s进入房间:%s 失败.当前总人数", session.getUser().nickName, roomid, room.roomUserSize()));
			return false;
		} finally {
			gameRoom.RoomDoorLock.unlock();
		}
	}

	public SessionObject getRoomSession(int index) {
		return gameRoom.roomUsers.get(index);
	}

	public UserInfoEntity getRoomUser(int index) {
		return gameRoom.roomUsers.get(index).getUser();
	}

	// ------RoomUsers---->
	// <----userSeats
	/**
	 * 当前坐位自动下移,并返回最新的坐位
	 * 
	 * @return
	 */
	public int nextSeat() {
		return gameRoom.nextSeat();
	}

	/**
	 * 只取下一个坐位，游标没有变化
	 * 
	 * @return
	 */
	public int getNextSeat() {
		return gameRoom.getNextSeat();
	}

	/**
	 * 根据上一个坐位找下一个坐位，游标没有变化
	 * 
	 * @return
	 */
	public int getNextSeat(int preSeatId) {
		return gameRoom.getNextSeat(preSeatId);
	}

	/**
	 * 当前坐位自动下移,并返回最新的session
	 * 
	 * @return
	 * */
	public SessionObject nextSession() {
		return gameRoom.nextSession();
	}

	/**
	 * 只取下一个坐位的session，游标没有变化
	 * 
	 * @return
	 * */
	public SessionObject getNextSession() {
		return gameRoom.getNextSession();
	}

	/**
	 * 当前坐位自动下移,并返回最新的user
	 * 
	 * @return
	 * */
	public UserInfoEntity nextUser() {
		return gameRoom.nextUser();
	}

	/**
	 * 只取下一个坐位的user，游标没有变化
	 * 
	 * @return
	 * */
	public UserInfoEntity getNextUser() {
		return gameRoom.getNextUser();
	}

	/**
	 * 只取下一个坐位的user，游标没有变化
	 * 
	 * @return
	 * */
	public UserInfoEntity getNextUser(int preSeatId) {
		return gameRoom.getNextUser(preSeatId);
	}

	// userSeats----->

	public float getSeatMaxRaise(int seatId) {
		//如果是最多筹码者，则取第2名的
		if (seatId == gameRoom.maxStakeSeat) {
			return gameRoom.getSecondStake();
		} else {
			return gameRoom.gameOverUsers[seatId - 1].maxRaiseStake();
		}
	}

	public int maxStakeSeat() {
		return gameRoom.maxStakeSeat;
	}

	public void setMaxStake() {
		gameRoom.setMaxStake();
	}

	/**
	 * 新回合开始，桌上chip清空，以及lastaction
	 */
	public void clearCallChip() {
		gameRoom.clearCallChip();
	}

	/**
	 * 新局开始，设置起始者 大盲开下一个
	 */
//	public void resetMaxRaiser() {
//		gameRoom.resetMaxRaiser();
//
//	}

	// <-----游戏结束-----
	//	public ArrayList<WinCardEntity> winCards() {
	//		return gameRoom.winCards;
	//	}

	//	public int winCardsSize() {
	//		return gameRoom.winCardsSize();
	//	}

	public UserGameEntity[] BonusWinner(int bonusIndex) {
		return gameRoom.BonusWinner(bonusIndex);
	}

	public byte winnerMapLen(int bonusIndex) {
		return gameRoom.winnerMapLen[bonusIndex];
	}

	public UserGameEntity[] allWinners() {
		return gameRoom.allWinners;
	}

	public byte allWinnersLen() {
		return gameRoom.allWinnersLen;
	}

	// 游戏结束----->

	public String getName() {
		return this.gameRoom.RoomName;
	}

	public void setName(String name) {
		//		this.name = name;
		this.gameRoom.RoomName = name;
	}

	public String getInfo() {
		return String.format("[Room]:%s,%s,[step:%s,sendStep:%s,AcceptStep:%s,curSeat:%s]最大小筹码%s %s,大小盲注%s %s [Game]:%s", this.id, this.isPlaying() ? "正在游戏" : "等待", this.step(), this.gameRoom.SendStep, this.gameRoom.AccepStep, this.curSeatId(), this.minTake, this.maxTake, this.minBlind, this.maxBlind, this.gameRoom.toString());
	}
}
